//MINI UI解析
mini.parse();

/**
 * 订单信息处理器类
 */
function InvoiceListHandler() {

}
//实例化全局订单处理器
InvoiceListHandler.instance = new InvoiceListHandler();
InvoiceListHandler.mgrData = new OrderMgrData();
InvoiceListHandler.orderQueryForm = new mini.Form("orderQueryForm");
InvoiceListHandler.isQueryBtnExpended = false;

InvoiceListHandler.orderGrid = mini.get("orderGrid");
InvoiceListHandler.orderGrid.url = InvoiceListHandler.mgrData.loadAllOrderListUrl("invoiceList");
InvoiceListHandler.orderPanel = mini.get("orderPanel");

//定义发货单列表页功能权限字符编码数组
InvoiceListHandler.purArrayInvList = new Array("order_fhd_query", "order_fhd_refresh", "order_fhd_detail");
	
/**
 * 功能按钮权限控制及其展示
 */
InvoiceListHandler.loadPurviewBtn = function() {
	var userArr = MiniuiTools.isHasPurview(InvoiceListHandler.purArrayInvList);
	
	for (var i = 0; i < userArr.length; i++) {
		var purviewBtn = mini.get(InvoiceListHandler.purArrayInvList[i]);
		
		if(purviewBtn){
			purviewBtn.setVisible(userArr[i]);
		}
	}
};

/**
 * 初始化数据
 */
InvoiceListHandler.init = function(){
	InvoiceListHandler.loadPurviewBtn();
	InvoiceListHandler.orderGrid.load();
};	

InvoiceListHandler.init();

/**
 * 展开、折叠查询按钮点击事件处理程序
 */
InvoiceListHandler.orderQuery = function() {
	if (InvoiceListHandler.isQueryBtnExpended) {
		InvoiceListHandler.isQueryBtnExpended = false;
		mini.get("order_fhd_query").setText("展开查询");
		mini.get("order_fhd_query").setIconCls("icon-btn-expand");
	} else {
		InvoiceListHandler.isQueryBtnExpended = true;
		mini.get("order_fhd_query").setText("收起查询");
		mini.get("order_fhd_query").setIconCls("icon-btn-collapse");
	}
	$("#queryOrderDiv").toggle(500);
	setTimeout(InvoiceListHandler.doLayout, 600);
};

/**
 * 智能调整界面布局
 */
InvoiceListHandler.doLayout = function(){
	InvoiceListHandler.orderPanel.doLayout();
}

/**
 * 查询订单点击事件处理程序
 */
InvoiceListHandler.queryOrderList = function() {
	var orderQueryData = mini.encode(InvoiceListHandler.orderQueryForm.getData());
	InvoiceListHandler.orderGrid.load({orderQueryData : orderQueryData});
}

/**
 * 刷新按钮点击事件处理程序
 */
InvoiceListHandler.afresh = function() {
	InvoiceListHandler.queryOrderList();
	InvoiceListHandler.doLayout();
}

/**
 * 查看详情点击事件处理程序
 */
InvoiceListHandler.findDetails = function(){
	if (!MiniuiTools.hasPurview("order_fhd_detail")) {
		mini.showMessageBox({title:"提示",message:"糟糕，您没有权限访问！",iconCls:"mini-messagebox-info",buttons: ["ok"]});
		return;
	}
	
	var rowData = InvoiceListHandler.orderGrid.getSelected();
	var boiId = rowData.boiId;
	var bmbId = rowData.boiMember;
	
	window.location.href="invoiceDetail.jsp?boiId="+boiId+"&bmbId="+bmbId;
}

/**
 * 表格绘画事件处理程序
 */
InvoiceListHandler.orderGrid.on("drawcell", function(e) {
	 var record = e.record;
     var column = e.column;
     var value = e.value;
     var innerHtml  = "";
     var indigoStr  = "<font style='color:#4B0082'>";
     var medblueStr = "<font style='color:#0000CD'>";
     var greenStr   = "<font style='color:#008000'>"; 
     var orgedStr   = "<font style='color:#FF0066'>";
     var redStr     = "<font style='color:#FF0000'>";
     var fontLas    = "</font>";
	
	switch (column.field) {
		case "boiOtime":
		{
			if(value != null && value != "") innerHtml = XMAppUtils.changeDateToDateTimeStr(value, false);
			break;
		}
		case "boiConsignee":
		{
			innerHtml = "<a href='#'>" + value + "</a>";
			break;
		}
		case "boiShip":
		{
			innerHtml = InvoiceListHandler.mgrData.boiShipData[value + 1].text;
			
			if(value == 0){
				innerHtml = greenStr + innerHtml + fontLas;
			}else if(value == 1 || value == 2){
				innerHtml = indigoStr + innerHtml + fontLas;
			}else if(value == 3){
				innerHtml = orgedStr + innerHtml + fontLas;
			}else if(value == 4){
				innerHtml = medblueStr + innerHtml + fontLas;
			}else if(value == 5 || value == 6){
				innerHtml = redStr + innerHtml + fontLas;
			}
			break;
		}
		case "boiOperate":
		{
			innerHtml = "<span><a style='cursor: pointer;' onclick='InvoiceListHandler.findDetails()'>详情</a></span>";
			break;
		}
		case "boiStime":
		{
			if(value != null && value != "") innerHtml = XMAppUtils.changeDateToDateTimeStr(value, false);
			break;
		}
	}
	
	if (innerHtml) e.cellHtml = innerHtml;
    
});


